<?php


namespace app\models;


use yii\base\Model;
use yii\web\UploadedFile;

class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $file;

    public $id;


    public function rules()
    {
        return [
            [['file'], 'file', 'skipOnEmpty' => false ],
        ];
    }

    public function upload()
    {


       if (!in_array($this->file->extension,["xls","xlsx","csv"])) {
             return false;
        }

        if ($this->validate()) {
            $filePath = '/app/act_manage_admin/img/aiunify/uploads/' . md5($this->id) . '.' . $this->file->extension;
            if ($this->file->saveAs($filePath)) {
                return 'https://img.bandai-card.com.cn/uploads/' . md5($this->id) . '.' . $this->file->extension;
            }


        }
       /* echo "文件扩展名: " . $this->file->extension;
        echo "文件 MIME 类型: " . $this->file->type;
        print_r($this->getErrors());*/
        return false;
    }
}